package com.cskaoyan.shopping.service.impl;

import com.cskaoyan.shopping.converter.ContentConverter;
import com.cskaoyan.shopping.dal.entitys.Panel;
import com.cskaoyan.shopping.dal.entitys.PanelContentItem;
import com.cskaoyan.shopping.dal.persistence.PanelContentMapper;
import com.cskaoyan.shopping.dal.persistence.PanelMapper;
import com.cskaoyan.shopping.dto.PanelContentItemDto;
import com.cskaoyan.shopping.dto.PanelDto;
import com.cskaoyan.shopping.service.IHomeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * \* User: 余雨健
 * \* Date: 2022/10/25
 * \* Time: 16:51
 **/
@Service
public class IHomeServiceImpl implements IHomeService {

    @Autowired
    PanelMapper panelMapper;
    @Autowired
    PanelContentMapper panelContentMapper;
    @Autowired
    ContentConverter contentConverter;

    /**
     *@
     *@author yuyujian
     *@Date 2022/10/26
     *@Time 17:40
     */
    @Override
    public Set<PanelDto> homepage() {
        Set<PanelDto> panelDtos = new HashSet<PanelDto>();
        List<Integer> integers = panelMapper.selectPanelIdByPosition(0);
        for (Integer integer : integers) {
            List<Panel> panels = panelMapper.selectPanelContentById(integer);
            Long productId = panels.get(0).getProductId();
            List<PanelContentItem> panelContentItems = panelContentMapper.selectPanelContentAndProductWithPanelId(integer);
            List<PanelContentItemDto> panelContentItemDtos = contentConverter.panelContentItem2Dto(panelContentItems);
            Panel panel = new Panel();
            panel = panels.get(0);
            PanelDto panelDto = contentConverter.panel2Dto(panel);
            panelDto.setPanelContentItems(panelContentItemDtos);
            panelDtos.add(panelDto);
        }
        return panelDtos;
    }
}
